Imports System.Configuration

''' -----------------------------------------------------------------------------
''' Project	 : BizBlox
''' Class	 : BizBlox.DOException
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' BizBlox Exception
''' </summary>
''' <remarks>
''' Using the application.config or web.config - 
''' value of Pixolut.BizBlox.Verbose contains a True or False.
''' </remarks>
''' <history>
''' 	[cinj]	10/09/2004	Created
''' </history>
''' -----------------------------------------------------------------------------
<Serializable()> _
Public Class DOException
    Inherits Exception

    Public Const msg As String = "BizBlox Exception."
    Public Const CONF_KEY As String = "Pixolut.BizBlox.Verbose"

    Public Sub New()
        MyBase.New(msg)
    End Sub ' New

    Public Sub New(ByVal Message As String)
        MyBase.New(String.Format("{0} - {1}", msg, Message))
    End Sub ' New

    Public Sub New(ByVal Message As String, ByVal inner As Exception)
        MyBase.New(String.Format("{0} - {1}", msg, Message), CType(IIf(Verbose, inner, New Exception("Inner Exception Suppressed.")), Exception))
    End Sub ' New

    Public Sub New(ByVal Message As String, ByVal SQLSrc As String, ByVal inner As Exception)
        MyBase.New(msg & " - " & Message & vbCrLf & vbCrLf & IIf(Verbose, "SQL Source: " & vbCrLf & SQLSrc, "SQL Source Suppressed."), CType(IIf(Verbose, inner, New Exception("Inner Exception Suppressed.")), Exception))
    End Sub ' New

    Private Shared m_cachedVerbosityLevel As Boolean
    Private Shared m_cached As Boolean
    Private Shared ReadOnly Property Verbose() As Boolean
        Get
            If m_cached <> True Then
                Try
                    Dim srcBuf As String = ConfigurationManager.AppSettings(CONF_KEY)
                    If srcBuf.ToLower() = "true" Or srcBuf.ToLower() = "1" Or srcBuf.ToLower() = "on" Then
                        m_cachedVerbosityLevel = True
                    Else
                        m_cachedVerbosityLevel = False
                    End If
                Catch ex As Exception
                    m_cachedVerbosityLevel = False
                End Try
                m_cached = True
            End If
            Return m_cachedVerbosityLevel
        End Get
    End Property

End Class
